package Servlet;
import DAO.DAOFactory;
import DAO.PackageDAO;
import javabean.Customer;
import javabean.CustomerPackage;
import javabean.Package;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import static sun.text.normalizer.Utility.escape;

@WebServlet("/Package_Delete")
public class Package_DeleteServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        PackageDAO packageDAO= (PackageDAO) DAOFactory.getPackageDAOInstance();
        HttpSession session = req.getSession();
        CustomerPackage Curpackage = (CustomerPackage) session.getAttribute("curPackage");
        try {
            packageDAO.CancellCustomerPackage(Curpackage);
            PrintWriter out = resp.getWriter();
            out.println("<script>");
            out.println("window.alert('" + escape("删除成功！") + "');");
            out.println("window.location.href='Personal_Info.jsp';"); // 在这里添加重定向到个人信息页面的代码
            out.println("</script>");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
